package com.epam.qanda.web.servlet.admin;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.epam.qanda.db.service.MessageService;

public class MessageFunctionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String path = request.getServletPath();
		Integer messageId = Integer.parseInt(request.getParameter("mId"));
		MessageService service = new MessageService();

		if (path.equals("/deleteMessage")) {
			service.delete(messageId);
		} else if (path.equals("/isReadMessage")) {
			service.setCheckedById(messageId);
		}

	}

}
